<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_shoufrom/model')->方法名();
*/
namespace jy_shoufrom;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function payresult($order=array(),$payresult=array(),$ispay=0,$yuejiemid=0){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$selfcount=pdo_count('jy_shoufrom_order',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'id');
		$daysnum=date('Ymd',time());
		$selfnumber='NO'.$daysnum.sprintf("%04d", $selfcount+1);
		$update=array(
			'status'=>1,
			'selfnumber'=>$selfnumber,
			'ispay'=>$ispay,
		);
		pdo_update('jy_shoufrom_order',$update,array('id'=>$order['id'],'uniacid'=>$_SESSION['uniacid']));
		$order['sendtype']=$order['type']?2:1;
		return false;
	}
	public function payresult4($order=array(),$payresult=array()){
		$update=array(
			'ispay'=>1,
		);
		pdo_update('jy_shoufrom_order',$update,array('id'=>$order['id'],'uniacid'=>$_SESSION['uniacid']));
		$this->order_receive($order['id']);
		return false;
	}
	public function uporder($order=array(),$status=0,$shifuid=0,$shifuremark='',$price=0){
		if($order['plugin']!='jy_shoufrom'){
			return false;
		}
		if($status==1){
			$status=9;
		}elseif($status==2){
			$status=2;
		}elseif($status==3){
			$status=4;
		}elseif($status==6){
			$status=10;
		}
		$update=array('status'=>$status);
		if($shifuid){
			$update['shifuid']=$shifuid;
		}
		if($shifuremark){
			$update['shifuremark']=$shifuremark;
		}
		if($price){
			$update['payfee']=$price;
		}
		pdo_update('jy_shoufrom_order',$update,array('id'=>$order['orderid'],'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function getorder($order=array(),$isinfo=0){
			$get_pay_types=get_pay_types();
			$item=pdo_get('jy_shoufrom_order',array('id'=>$order['orderid'],'uniacid'=>$_SESSION['uniacid']));
			$item['member']=cfc('core')->member_show($item['mid']);
			$store=pdo_get('jy_weishop_store',array('id'=>$item['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title','mobile','tel','address','pcd'));	
			$item['store']=$store;
			$item['goods']=pdo_getall('jy_shoufrom_list',array('id'=>$item['pid'],'uniacid'=>$_SESSION['uniacid']));
			$item['user_name']=$item['username'];
			$item['user_mobile']=$item['mobile'];
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			$item['ispaytitle']=$item['ispay']?'已支付':'未支付';
			$item['paytype']=pdo_getcolumn('core_paylog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pay_id']),'pay_type');
			$item['paytypetitle']=$get_pay_types[$item['paytype']];
			//用户地址
			$item['addresstext']=$item['address'];
			if($item['goods']){
				foreach($item['goods'] as &$g){
					$g['totalprice']=$g['price'];
					$g['goods_title']=$g['title'];
					$item['goods_num'] +=1;
					$g['image']=tomedia($g['image']);
				}
			}
			$item['serve_time']=date('Y-m-d H:i:s', $item['serve_time']);
			if($isinfo){
				$item['images']=json_decode($item['images'],true);
				foreach($item['images'] as &$p){
					$p=tomedia($p);
				}
				$item['fileds']=json_decode($item['fileds'],true);
			}
			return $item;
	}
	public function order_receive($orderid=0){
		pdo_update('jy_shoufrom_order',array('status'=>8),array('uniacid'=>$_SESSION['uniacid'],'id'=>$orderid));
		return false;
	}
}
?>